package cs2340.droidceptiontodo.test;

import cs2340.droidceptiontodo.AddToDoItemActivity;
import cs2340.droidceptiontodo.UserAccount;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AddToDoItemActivityTest2 extends ActivityInstrumentationTestCase2<AddToDoItemActivity>{

	
	private AddToDoItemActivity activity;
	private TextView dateView, timeView;
	private Button chooseDateButton, clearDateButton, chooseTimeButton, clearTimeButton,
					addItemButton, cancelButton;
	private EditText nameField, descriptionField, categoryField, locationField;
	private UserAccount user;
	
	public AddToDoItemActivityTest2() {
		// Android uses this information to find the application and activity to test.
		super("cs2340.droidceptiontodo", AddToDoItemActivity.class);
	}
	
	protected void setUp() throws Exception {
		
		super.setUp();
		// Touch mode must be turned off in order to test
		// key events
		setActivityInitialTouchMode(false);
		// Gets reference to AddToDoItemActivity and starts activity
		activity = (AddToDoItemActivity) getActivity();
				
		// Get references to widgets under test
		dateView = (TextView) activity.findViewById(cs2340.droidceptiontodo.R.id.dateView);
		timeView = (TextView) activity.findViewById(cs2340.droidceptiontodo.R.id.timeView);
		chooseDateButton = (Button) activity.findViewById(cs2340.droidceptiontodo.R.id.chooseDateButton);
		clearDateButton = (Button) activity.findViewById(cs2340.droidceptiontodo.R.id.clearDateButton);
		chooseTimeButton = (Button) activity.findViewById(cs2340.droidceptiontodo.R.id.chooseTimeButton);
		clearTimeButton = (Button) activity.findViewById(cs2340.droidceptiontodo.R.id.clearTimeButton);		
		nameField = (EditText) activity.findViewById(cs2340.droidceptiontodo.R.id.name);
		descriptionField = (EditText)  activity.findViewById(cs2340.droidceptiontodo.R.id.description);
		categoryField = (EditText) activity.findViewById(cs2340.droidceptiontodo.R.id.category);
		locationField = (EditText) activity.findViewById(cs2340.droidceptiontodo.R.id.location);
		addItemButton = (Button) activity.findViewById(cs2340.droidceptiontodo.R.id.addItemButton);
		cancelButton = (Button) activity.findViewById(cs2340.droidceptiontodo.R.id.cancelButton);
		
		
	}
	
	public void testPreConditions() {
		// Make sure activity and widgets are not null
		assertNotNull(nameField);
		assertNotNull(descriptionField);
		assertNotNull(categoryField);
		assertNotNull(locationField);
		assertNotNull(chooseDateButton);
		assertNotNull(clearDateButton);
		assertNotNull(chooseTimeButton);
		assertNotNull(clearTimeButton);
		assertNotNull(addItemButton);
		assertNotNull(cancelButton);
		assertNotNull(dateView);
		assertNotNull(timeView);
		
	}
	@UiThreadTest
	public void testOnCreate() {
					
		nameField.setText("New To-Do Item");
		descriptionField.setText("Item description goes here.");
		categoryField.setText("School");
		locationField.setText("Georgia Tech");
		
		// Set and get text from text fields
		String name = nameField.getText().toString();
		assertTrue("Name set: ", name.equals("New To-Do Item"));
		String description = descriptionField.getText().toString();
		assertTrue("Description set: ",description.equals("Item description goes here."));
		String category = categoryField.getText().toString();
		assertTrue("Category set: ", category.equals("School"));
		String location = locationField.getText().toString();
		assertTrue("Location set: ",location.equals("Georgia Tech"));
		assertTrue("Choose date button clickable: ", chooseDateButton.isClickable());	
		assertTrue("Clear date button clickable: ",clearDateButton.isClickable());	
		assertTrue("Choose time button clickable: ",chooseTimeButton.isClickable());	
		assertTrue("Clear time button clickable: ",clearTimeButton.isClickable());	
		assertTrue("Add item button clickable: ",addItemButton.isClickable());	
		assertTrue("Cancel button clickable: ",cancelButton.isClickable());	
		
	}
	
	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	
}

